package org.farm2.test.utils;

import lombok.extern.slf4j.Slf4j;
import org.farm2.base.jwt.FarmJwtClaims;
import org.farm2.base.jwt.FarmJwtConfig;
import org.farm2.base.jwt.FarmJwtUtils;
import org.farm2.tools.json.FarmJsons;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.farm2.base.jwt.FarmJwtUtils.getJwtRemainingTime;


@ExtendWith(SpringExtension.class) // 启用 Spring TestContext 框架
@Slf4j
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class Hsa256Tester {
    private static String token = null;

    @Test
    @Order(1)
    void creatToken() {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest("haha".getBytes());
            StringBuilder hexString = new StringBuilder();
            for (byte b : hash) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) hexString.append('0');
                hexString.append(hex);
            }
            token = hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        System.out.println(token);
        assertThat(token).isNotNull();
    }


}
